(function() {
  "use strict";
  APP.Views.UserInfoView = Backbone.View.extend({
    el: '#userContainer',
    events : {
      'mouseenter .avatar': 'zoomIn',
      'mouseleave .avatar': 'zoomOut',
      // 'click .com-management': 'comManagementShow',
      // 'click .gotoSettings': 'gotoSettings',
      // 'click .gotoGroup': 'gotoGroups'
      'click a': 'stop'
    },
    initialize: function(params) {
      // var callback = {
      //   obj: this,
      //   name: 'getUserDataSuccess'
      // }
      // APP.BeClient.getUserData(callback, undefined, {
      //   preloaderShow: false,
      //   preloaderHide: false
      // });
      this.getUserDataSuccess();
    },
    stop: function(e) {
      e.preventDefault();
    },
    getUserDataSuccess: function(data) {
      var user = {
        "email":"admin@domena.pl",
        "company":"Volkswagen Group Polska",
        "department":"Zarz\u0105d",
        "phone":"0525371927",
        "mobile":"111222333",
        "photo":"http:\/\/th168.photobucket.com\/albums\/u194\/illuminarch\/th_CapAvatar-1.jpg",
        "isActive":true,
        "lastLogin":"15:25:48 06.05.2014",
        "group":{
          "id":1,
          "name":"Podstawowa",
          "isBasic":true
        },
        "id":2,
        "fname":"Jan",
        "lname":"Kowalski",
        "role":1
      }
      this.render(user);
    },
    zoomIn: function(e) {
      var $e = $(e.currentTarget);
      $e.stop().animate({'height': 150});
    },
    zoomOut: function(e) {
      var $e = $(e.currentTarget);
      $e.stop().animate({'height': 50});
    },
    comManagementShow: function(e) {
      e.preventDefault();
      new APP.Views.DialogComManagementView({
        menuView: APP.mainView
      });
    },
    gotoSettings: function(e) {
      e.preventDefault();
      Backbone.history.navigate("uzytkownicy", {
        trigger: true
      });
    },
    gotoGroups: function(e) {
      e.preventDefault();
      Backbone.history.navigate("grupy", {
        trigger: true
      });
    },
    render: function(user) {
      var self = this;
      this.$el.html(_.template($('#userInfoTemplate').html(), {
        user: user
      }));
      this.$('.show-more-info').popover({
        html: true,
        placement: 'bottom',
        content: _.template($('#userInfoMoreTemplate').html(), {
          user: user
        }),
        trigger: 'focus'
      });
      self.$('.set-margin').css('marginRight', $('img.avatar').width() - 15);
      this.$('img.avatar').imgpreload(function() {
        self.$('.set-margin').css('marginRight', $(this).width() - 15);
      });
      return this;
    }
  });
}());